export function submit(data: any): Promise<any> {
    if(!data ||!data.table_id || !data.data) return Promise.reject(new Error('参数不完整'))
    if(data.data.id){
        return update(data.table_id,data.data);
    }else{
        return add(data.table_id,data.data);
    }
}

export function update(tableId:string|number,data: any): Promise<any> {
    const url = '/biz/form/update';
    return new Promise((resolve, reject) => {
        window.$theia.http
            .post(url, {table_id:tableId,param:data})
            .then((response: any) => {
                resolve(response);
            })
            .catch((err: any) => {
                reject(err);
            });
    });
}
export function add(tableId:string|number,data: any): Promise<any> {
    const url = '/biz/form/add';
    return new Promise((resolve, reject) => {
        window.$theia.http
            .post(url, {table_id:tableId,param:data})
            .then((response: any) => {
                resolve(response);
            })
            .catch((err: any) => {
                reject(err);
            });
    });
}
export function query(tableId:string|number,data: any,pi:number=1,ps:number=10): Promise<any> {
    const url = '/biz/form/query';
    return new Promise((resolve, reject) => {
        window.$theia.http
            .post(url, {"table_id":tableId,param:data,pi,ps})
            .then((response: any) => {
                resolve(response);
            })
            .catch((err: any) => {
                reject(err);
            });
    });
}
